
local CommonOHOH = _G.CommonOHOH;
local M = CommonOHOH.class.new(script, CommonOHOH.files.BaseObject());
local ConnectClass = CommonOHOH.load.Connect();
-- local ISCLient=game:GetService("RunService"):IsClient()
-- local gBuffGui=nil
-- if ISCLient then
--     gBuffGui= _G.ClientOHOH.load.UIManager():CreateUI("BuffGui",require(script.Parent.BuffGui))
-- end

function M.new(self,...)
	return M(self,...);
end;
function M.ctor(self,bid,player,time)
    self.buffId=bid
    -- self.IsClient= ISCLient
	M.super.ctor(self);
    self.DestroyEvent=ConnectClass.new()
    self.UpdateEvent=ConnectClass.new()

    self.player=player
    self.waitTime=time


    -- self.WaitConnect=self:AddProcess(function()
    --     self:Wait(time)
    --     self:dtor()
    -- end)

    self.WaitConnect=self:AddStepUpdate(self.Update,1)

    self:Use()

    -- if  self.IsClient then
    --     self:CreateUI()
    -- end
end;



function M.Update(self)
    self.waitTime=self.waitTime-1
    self.UpdateEvent:Action(self.waitTime)
    if  self.waitTime<=0 then
        self:dtor()
    end
end

function M.GetId(self)
    return  self.buffId
end


function M.TimeLeft(self)
    return self.waitTime
end


function M.Use(self)

end


-- function M.CreateUI(self)
--   self.BuffGui=gBuffGui:CreatCellShow(self.buffId,self.waitTime)
-- end


function M.Add(self,t)
    self.waitTime=self.waitTime+t

    self.UpdateEvent:Action(self.waitTime)

    -- if  self.IsClient then
    --     self.BuffGui:Add(t)
    -- end

end


function M.dtor(self)
    
    if self.WaitConnect then
        self.WaitConnect:Disconnect()
        self.WaitConnect=nil
    end

    self.DestroyEvent:Action(self)

    if  self.IsClient then
        self.BuffGui:dtor()
    end

    self:AddProcess(function()
        self.DestroyEvent:dtor()
        self.UpdateEvent:dtor()
        M.super.dtor(self);
    end)

end;

return M;
